#include <linux/sched.h>
#include <linux/pgtable.h>

#include <asm/switch_to.h>

static inline void finish_lock_switch(struct rq *rq)
{
    raw_spin_rq_unlock_irq(rq);
}

static inline void prepare_task_switch(struct rq *rq, struct task_struct *prev,
                                       struct task_struct *next)
{
}

static struct rq *finish_task_switch(struct task_struct *prev)
{
    struct rq *rq = task_rq(prev);

    finish_lock_switch(rq);

    return rq;
}

/*
 * context_switch - switch to the new MM and the new thread's register state.
 */
static inline struct rq *context_switch(struct rq *rq, struct task_struct *prev,
                                        struct task_struct *next, struct rq_flags *rf)
{
    prepare_task_switch(rq, prev, next);

    /*
     * For paravirt, this is coupled with an exit in switch_to to
     * combine the page table reload and the switch backend into
     * one hypercall.
     */
    arch_start_context_switch(prev);

    /* Here we just switch the register state and the stack. */
    switch_to(prev, next, prev);
    barrier();

    return finish_task_switch(prev);
}
